package me.ezitku.base.Socket.Tcp

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.net.Socket

/**
 * Created by yurqi on 2017/6/2.
 */


fun InputStream.toString(action: (String) -> Unit) {
    var buffered = BufferedReader(InputStreamReader(this))
    var result = ""
    do {
        result = buffered.readLine()
    } while (result != null)

    action.invoke(result)
}

fun Socket.getMessage(action: (String) -> Unit) = getInputStream().toString(action)